package com.sample.wanandroidx.ui.home

import android.content.Intent
import com.sample.wanandroidx.app.App
import com.sample.wanandroidx.basic.BaseActivity
import com.sample.wanandroidx.databinding.ActivityStartBinding
import com.sample.wanandroidx.ext.startActivity

////使用AppCompatActivity减少初始化时间
class StartActivity : BaseActivity<ActivityStartBinding>(ActivityStartBinding::inflate) {

    override fun initialization() {
        if (intent.flags and Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT != 0) {
            finish()
        } else {
            postDelayed(1000) {
                goToMainActivity()
            }
        }

    }

    private fun goToMainActivity() {
        when (App.user == null) {
            true -> {
                //                startActivity<LoginActivity>()
                startActivity<ModifyTimeActivity>()
            }
            false -> {
                startActivity<ModifyTimeActivity>()
                //                startActivity<ModifyTimeActivity>()
            }
        }
        finish()
    }

    override fun onBackPressed() {
        super.onBackPressed()
        getHandler()?.removeCallbacksAndMessages(null)
    }

    override fun onDestroy() {
        super.onDestroy()
    }
}